<template>
  <el-submenu v-if="menu.children && menu.children.length >= 1" :index="'' + menu.id">
    <template slot="title">
<!--      <i :class="menu.icon" ></i>-->
      <icon-svg :name="menu.icon"></icon-svg>
      <span slot="title">{{menu.menuTitle}}</span>
    </template>
    <MenuTree v-for="item in menu.children" :key="item.id" :menu="item"></MenuTree>
  </el-submenu>
  <el-menu-item v-else :index="'' + menu.id" @click="handleRoute(menu)">
    <icon-svg :name="menu.icon"></icon-svg>
<!--    <i :class="menu.icon"></i>-->
    <span slot="title">{{menu.menuTitle}}</span>
  </el-menu-item>
</template>

<script>
import { getIFrameUrl, getIFramePath } from '@/utils/iframe'
export default {
  name: 'MenuTree',
  props: {
    menu: {
      type: Object,
      required: true
    }
  },
  methods: {
    handleRoute (menu) {
      // 如果是嵌套页面，转换成iframe的path
      let path = getIFramePath(menu.pathUrl)
      if(!path) {
        path = menu.pathUrl
      }
      // 传染病上报卡跳转到新的界面
      if (menu.menuTitle === '传染病报告卡') {
        const newUrl = this.$router.resolve({
          path: '/hospital/reportcard'
        })
        // 打开新的界面
        window.open(newUrl.href, '_blank')
      } else {
        this.$router.push("/" + path)
        // 通过菜单URL跳转至指定路由
      }
    }
  }
}
</script>

<style scoped lang="scss">
// .el-submenu, .el-menu-item {
//   background-color: #3c4b5a44;
// }
</style>
